import { resolveMx } from "dns";
import { AccountDailyLogin } from "../account_server/dao/AccountDailyLogin";
import { AccountDailyRegister } from "../account_server/dao/AccountDailyRegister";
import { AccountDao } from "../account_server/dao/AccountDao";
import { UserDao } from "../account_server/dao/UserDao";
import { AccountModel } from "../account_server/model/AccountModel";
import { ClubDao } from "../hall_server/dao/ClubDao";
import { RoomDao } from "../hall_server/dao/RoomDao";
import { RoomResultDao } from "../hall_server/dao/RoomResultDao";
import { RoomTemplateDao } from "../hall_server/dao/RoomTemplateDao";
import { RoomVideoDao } from "../hall_server/dao/RoomVideoDao";
import { HallServer_SocketMsgHandler } from "../hall_server/HallServer_SocketMsgHandler";
import { RoomModel } from "../hall_server/model/RoomModel";
import { RoomTemplateModel } from "../hall_server/model/RoomTemplateModel";
import { ClubTopDao } from "../log_server/dao/ClubTopDao";
import { Daily_ResourceDao } from "../log_server/dao/Daily_ResourceDao";
import { RoomStatisticsDao } from "../log_server/dao/RoomStatisticsDao";
import { User_Coins_HistoryDao } from "../log_server/dao/User_Coins_HistoryDao";
import { User_Gems_HistoryDao } from "../log_server/dao/User_Gems_HistoryDao";
import { User_Meilis_HistoryDao } from "../log_server/dao/User_Meilis_HistoryDao";
import { User_Spend_DailyDao } from "../log_server/dao/User_Spend_DailyDao";
import { LogServerHelper } from "../log_server/LogServerHelper";
import { ChargeDao } from "../pay_server/dao/ChargeDao";
import { Config } from "../src/config/Config";
import { ErrorCode } from "../src/config/ErrorCode";
import { GameConfig } from "../src/config/GameConfig";
import { GoodConfig } from "../src/config/GoodConfig";
import { RoomConfig } from "../src/config/RoomConfig";
import { RoomJinbiConfig } from "../src/config/RoomJinbiConfig";
import { ServerConfig } from "../src/config/ServerConfig";
import DateUtil from "../src/engine/utils/DateUtil";
import { HttpUtil } from "../src/engine/utils/HttpUtil";
import { Logger } from "../src/engine/utils/Logger";
import { Md5Helper } from "../src/engine/utils/Md5Helper";
import { WebUtil } from "../src/engine/utils/WebUtil";
import { GameImgHelper } from "../src/game/helper/GameImgHelper";
import { ResponseModel } from "../src/model/ResponseModel";
import { SystemSettingModel } from "../src/model/SystemSettingModel";
import { ServerManager } from "../src/server/ServerManager";
import { LogCoinDao } from "./dao/LogCoinDao";
import { LogGemDao } from "./dao/LogGemDao";
import { SystemSettingDao } from "./dao/SystemSettingDao";
import { GmUserModel } from "./model/GmUserModel";
const request = require('request');
const crypto = require("crypto");
const multer = require('multer');

const routerMap = {
    login: "/login",
    get_main_statistics_info: "/get_main_statistics_info",
    get_account_list: "/get_account_list",
    search_account: "/search_account",
    get_account_register: "/get_account_register",
    get_account_login: "/get_account_login",
    get_account_keep: "/get_account_keep",

    get_user_list: "/get_user_list",
    get_user_info: "/get_user_info",
    get_user_normal_daili_list: "/get_user_normal_daili_list",
    get_user_qudao_daili_list: "/get_user_qudao_daili_list",
    charge_by_gm: "/charge_by_gm",
    fengjin_user: "/fengjin_user",
    set_normal_daili: "/set_normal_daili",
    set_qudao_daili: "/set_qudao_daili",
    req_invite_list: "/req_invite_list",
    get_log_gem_date: "/get_log_gem_date",
    get_log_gem_week: "/get_log_gem_week",
    get_log_gem_month: "/get_log_gem_month",

    get_log_coin_date: "/get_log_coin_date",
    get_log_coin_week: "/get_log_coin_week",
    get_log_coin_month: "/get_log_coin_month",

    game_date_charge_data: "/game_date_charge_data",
    game_week_charge_data: "/game_week_charge_data",
    game_month_charge_data: "/game_month_charge_data",
    get_user_spend: "/get_user_spend",
    update_system_setting: "/update_system_setting",
    get_system_setting: "/get_system_setting",
    get_notice: "/get_notice",
    get_choushui: "/get_choushui",
    get_gems_detail: "/get_gems_detail",
    get_coins_detail: "/get_coins_detail",
    get_meilis_detail: "/get_meilis_detail",
    get_daily_resource: "/get_daily_resource",

    set_allserver_status: "/set_allserver_status",
    get_gm_server_status: "/get_gm_server_status",
    set_gameserver_status: "/set_gameserver_status",
    get_gameserver_status: "/get_gameserver_status",

    create_ziyou_room_template: "/create_ziyou_room_template",
    get_ziyou_room_template: "/get_ziyou_room_template",
    delete_ziyou_room_template: "/delete_ziyou_room_template",

    clear_weihu_room: "/clear_weihu_room",
    fix_club_top: "/fix_club_top",
    kill_all_users: "/kill_all_users",

    get_zhanji: "/get_zhanji",
    get_zhanji_detail: "/get_zhanji_detail",
    unbind: "/unbind",
    upload_img: "/upload_img",
    get_room_statistics: "/get_room_statistics",

}

export class GmReqHandler {

    public static instance: GmReqHandler = new GmReqHandler();


    public init(app) {
        for (const key in routerMap) {
            if (routerMap[key] == routerMap.upload_img) {
                app.post(routerMap.upload_img, multer().single('file'), this.on_upload_img.bind(this));
            } else {
                app.use(routerMap[key], this.onBaseRoot.bind(this))
            }
        }

    }

    private onBaseRoot(req, resp) {
        try {
            let ip: string = WebUtil.getIpByExpressReq(req);
            Logger.log("onBaseRoot=req=", ip, req.baseUrl)
            if (req.baseUrl == routerMap.login) {
                this.checkBody(ip, req, resp, this.on_login.bind(this));
            }
            else if (req.baseUrl == routerMap.set_allserver_status) {
                this.checkBody_md5(ip, req, resp, this.set_allserver_status.bind(this));
            }
            else if (req.baseUrl == routerMap.set_gameserver_status) {
                this.checkBody_md5(ip, req, resp, this.set_gameserver_status.bind(this));
            }
            else if (req.baseUrl == routerMap.get_gameserver_status) {
                this.checkBody_md5(ip, req, resp, this.get_gameserver_status.bind(this));
            }
            else if (req.baseUrl == routerMap.get_gm_server_status) {
                this.checkBody_md5(ip, req, resp, this.get_gm_server_status.bind(this));
            }
            else if (req.baseUrl == routerMap.get_main_statistics_info) {
                this.checkBody_md5(ip, req, resp, this.on_get_main_statistics_info.bind(this));
            }
            else if (req.baseUrl == routerMap.get_account_list) {
                this.checkBody_md5(ip, req, resp, this.on_get_account_list.bind(this));
            }
            else if (req.baseUrl == routerMap.search_account) {
                this.checkBody_md5(ip, req, resp, this.on_search_account.bind(this));
            }
            else if (req.baseUrl == routerMap.get_account_register) {
                this.checkBody_md5(ip, req, resp, this.on_get_account_register.bind(this));
            }
            else if (req.baseUrl == routerMap.get_account_login) {
                this.checkBody_md5(ip, req, resp, this.on_get_account_login.bind(this));
            }
            else if (req.baseUrl == routerMap.get_account_keep) {
                this.checkBody_md5(ip, req, resp, this.on_get_account_keep.bind(this));
            }
            else if (req.baseUrl == routerMap.get_user_list) {
                this.checkBody_md5(ip, req, resp, this.on_get_user_list.bind(this));
            }
            else if (req.baseUrl == routerMap.get_user_normal_daili_list) {
                this.checkBody_md5(ip, req, resp, this.on_get_user_normal_daili_list.bind(this));
            }
            else if (req.baseUrl == routerMap.get_user_qudao_daili_list) {
                this.checkBody_md5(ip, req, resp, this.on_get_user_qudao_daili_list.bind(this));
            }
            else if (req.baseUrl == routerMap.get_user_info) {
                this.checkBody_md5(ip, req, resp, this.on_get_user_info.bind(this));
            }
            else if (req.baseUrl == routerMap.charge_by_gm) {
                this.checkBody_md5(ip, req, resp, this.on_charge_by_gm.bind(this));
            }
            else if (req.baseUrl == routerMap.fengjin_user) {
                this.checkBody_md5(ip, req, resp, this.on_fengjin_user.bind(this));
            }
            else if (req.baseUrl == routerMap.set_normal_daili) {
                this.checkBody_md5(ip, req, resp, this.on_set_normal_daili.bind(this));
            }
            else if (req.baseUrl == routerMap.set_qudao_daili) {
                this.checkBody_md5(ip, req, resp, this.on_set_qudao_daili.bind(this));
            }
            else if (req.baseUrl == routerMap.req_invite_list) {
                this.checkBody_md5(ip, req, resp, this.on_req_invite_list.bind(this));
            }
            else if (req.baseUrl == routerMap.get_log_gem_date) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_gem_date.bind(this))
            }
            else if (req.baseUrl == routerMap.get_log_gem_week) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_gem_week.bind(this))
            }
            else if (req.baseUrl == routerMap.get_log_gem_month) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_gem_month.bind(this))
            }
            else if (req.baseUrl == routerMap.get_log_coin_date) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_coin_date.bind(this))
            }
            else if (req.baseUrl == routerMap.get_log_coin_week) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_coin_week.bind(this))
            }
            else if (req.baseUrl == routerMap.get_log_coin_month) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_coin_month.bind(this))
            }
            else if (req.baseUrl == routerMap.game_date_charge_data) {
                this.checkBody_md5(ip, req, resp, this.on_game_date_charge_data.bind(this));
            }
            else if (req.baseUrl == routerMap.game_week_charge_data) {
                this.checkBody_md5(ip, req, resp, this.on_game_week_charge_data.bind(this));
            }
            else if (req.baseUrl == routerMap.game_month_charge_data) {
                this.checkBody_md5(ip, req, resp, this.on_game_month_charge_data.bind(this));
            }
            else if (req.baseUrl == routerMap.get_user_spend) {
                this.checkBody_md5(ip, req, resp, this.on_get_user_spend.bind(this));
            }
            else if (req.baseUrl == routerMap.get_room_statistics) {
                this.checkBody_md5(ip, req, resp, this.on_get_room_statistics.bind(this));
            }
            else if (req.baseUrl == routerMap.update_system_setting) {
                this.checkBody_md5(ip, req, resp, this.on_update_system_setting.bind(this))
            }
            else if (req.baseUrl == routerMap.get_system_setting) {
                this.checkBody_md5(ip, req, resp, this.on_get_system_setting.bind(this))
            }
            else if (req.baseUrl == routerMap.get_choushui) {
                this.checkBody_md5(ip, req, resp, this.on_get_choushui.bind(this))
            }
            else if (req.baseUrl == routerMap.get_notice) {
                this.checkBody_md5(ip, req, resp, this.on_get_notice.bind(this))
            }
            else if (req.baseUrl == routerMap.get_gems_detail) {
                this.checkBody_md5(ip, req, resp, this.on_get_gems_detail.bind(this))
            }
            else if (req.baseUrl == routerMap.get_coins_detail) {
                this.checkBody_md5(ip, req, resp, this.on_get_coins_detail.bind(this))
            }
            else if (req.baseUrl == routerMap.get_meilis_detail) {
                this.checkBody_md5(ip, req, resp, this.on_get_meilis_detail.bind(this))
            }
            else if (req.baseUrl == routerMap.get_daily_resource) {
                this.checkBody_md5(ip, req, resp, this.on_get_daily_resource.bind(this))
            }
            else if (req.baseUrl == routerMap.create_ziyou_room_template) {
                this.checkBody_md5(ip, req, resp, this.on_create_ziyou_room_template.bind(this))
            }
            else if (req.baseUrl == routerMap.get_ziyou_room_template) {
                this.checkBody_md5(ip, req, resp, this.on_get_ziyou_room_template.bind(this))
            }
            else if (req.baseUrl == routerMap.delete_ziyou_room_template) {
                this.checkBody_md5(ip, req, resp, this.on_delete_ziyou_room_template.bind(this))
            }
            else if (req.baseUrl == routerMap.clear_weihu_room) {
                this.checkBody_md5(ip, req, resp, this.on_clear_weihu_room.bind(this))
            }
            else if (req.baseUrl == routerMap.fix_club_top) {
                this.checkBody_md5(ip, req, resp, this.fix_club_top.bind(this))
            }
            else if (req.baseUrl == routerMap.kill_all_users) {
                this.checkBody_md5(ip, req, resp, this.kill_all_users.bind(this))
            }
            else if (req.baseUrl == routerMap.get_zhanji) {
                this.checkBody_md5(ip, req, resp, this.get_zhanji.bind(this))
            }
            else if (req.baseUrl == routerMap.get_zhanji_detail) {
                this.checkBody_md5(ip, req, resp, this.get_zhanji_detail.bind(this))
            }
            else if (req.baseUrl == routerMap.unbind) {
                this.checkBody_md5(ip, req, resp, this.on_unbind.bind(this))
            }

        } catch (error) {
            Logger.warn("onBaseRoot error", error);
        }
    }

    private checkBody(ip: string, req, resp, callback: Function) {
        if (req.body) {
            try {
                let jsonObj = JSON.parse(req.body);
                callback && callback(req, resp, jsonObj, ip);
            } catch (error) {
                Logger.error("收到非法Http请求body", ip, req.body, error)
                resp.end();
            }
        }
        else {
            resp.end();
        }
    }

    private checkBody_md5(ip: string, req, resp, callback: Function) {
        if (req.body) {
            try {
                let jsonObj = JSON.parse(req.body);
                let k: string = jsonObj["k"];
                let data: object = jsonObj["data"]
                if (k == Md5Helper.getMd5_encrypt(JSON.stringify(data))) {
                    let user: GmUserModel = this.checkToken(data["token"], resp)
                    if (user) {
                        callback && callback(req, resp, data, ip, user);
                    }
                }
                else {
                    Logger.warn("收到非法Http请求 key", ip, req.body)
                    resp.end();
                }
            } catch (error) {
                Logger.warn("收到非法Http请求body", ip, req.body, error)
                resp.end();
            }
        }
        else {
            resp.end();
        }
    }


    private checkToken(token: string, resp, req = null) {
        let user: GmUserModel = GmUserModel.getUserByToken(token)
        if (user) {
            return user;
        }
        let respModel: ResponseModel = new ResponseModel()
        respModel.code = ErrorCode.Code.LoginError_token
        respModel.msg = "token已过期"
        resp.end(JSON.stringify(respModel));
        return null;
    }


    private async on_upload_img(req, resp, ip: string) {
        Logger.log("on_upload_img==", req)
        let token: string = req.query["token"]
        if (this.checkToken(token, resp, req)) {
            let respModel: ResponseModel = new ResponseModel()
            let userid: number = req.query["userid"]
            if (req.file) {
                let buffer = req.file.buffer;
                let uploadType: number = GameConfig.upload_pic_type.Img1
                let imgurl: string = GameImgHelper.buffer_to_imgurl(userid, uploadType, buffer)
                // respModel = await HallServer_SocketMsgHandler.saveUploadImg(imgurl, uploadType, userid, GameConfig.Account_Type.Account)
                if (respModel.code == ErrorCode.Code.Suc) {
                    ServerManager.instance.notify_update_img(userid, imgurl, uploadType)
                }
            }
            else {
                respModel.code = ErrorCode.Code.Fail
                respModel.msg = "不存在上传文件"
            }
            resp.end(JSON.stringify(respModel))
        }
    }

    /**
     * @param req 用户登录
     * @param resp 
     * @param data 
     * @param ip 
     */
    private async on_login(req, resp, data: object, ip: string) {
        // Logger.log("onLogin==", req, ip, req.query, req.body)
        let userName: string = data["userName"];
        let pass: string = data["pass"];
        let respModel: ResponseModel = await GmUserModel.checkLogin(userName, pass);
        resp.end(JSON.stringify(respModel));
    }


    private async on_get_main_statistics_info(req, resp, data: object, ip: string) {
        Logger.log("on_get_main_statistics_info==", data, ip)
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = await UserDao.get_main_statistics_info()
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_account_list(req, resp, data: object, ip: string) {
        let pagenum: number = data["pagenum"]
        let pagesize: number = data["pagesize"]
        let respModel: ResponseModel = new ResponseModel()
        let resultObj: object = {
        }
        resultObj["accounts"] = await AccountDao.get_account_list(pagenum, pagesize)
        resultObj["count"] = await AccountDao.getAccountNum()
        respModel.data = resultObj
        resp.end(JSON.stringify(respModel));
    }


    private async on_search_account(req, resp, data: object, ip: string) {
        let searchKey: string = data["searchKey"]
        let searchValue: string = data["searchValue"]
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = await AccountDao.search_account(searchKey, searchValue);
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_account_register(req, resp, data: object, ip: string) {
        let startDate: number = data["startDate"]
        let endDate: number = data["endDate"]
        let respModel: ResponseModel = new ResponseModel()
        let startDateStr: string = DateUtil.formatDateStr3(startDate)
        let endDateStr: string = DateUtil.formatDateStr3(endDate)
        let list: Array<object> = await AccountDailyRegister.getAccountRegister(startDateStr, endDateStr);
        let totalDay: number = Math.floor((endDate - startDate) / Config.OneDay) + 1;
        let resultList: Array<object> = []
        for (let i = 0; i < totalDay; i++) {
            let defaultTime: Date = new Date(startDate)
            defaultTime.setHours(0)
            defaultTime.setMinutes(0)
            defaultTime.setSeconds(0)
            let obj: object = {
                "date": DateUtil.formatDateStr3(defaultTime.getTime() + Config.OneDay * i)
            }

            let count: number = 0
            for (let mm = 0; mm < list.length; mm++) {
                let date_stampDate: Date = new Date(list[mm]["date"])
                if (DateUtil.formatDateStr3(date_stampDate.getTime()) == obj["date"]) {
                    count++
                }
            }
            obj["count"] = count
            resultList[i] = obj
        }
        respModel.data = resultList
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_account_login(req, resp, data: object, ip: string) {
        let startDate: number = data["startDate"]
        let endDate: number = data["endDate"]
        let respModel: ResponseModel = new ResponseModel()
        let startDateStr: string = DateUtil.formatDateStr3(startDate)
        let endDateStr: string = DateUtil.formatDateStr3(endDate)
        let list: Array<object> = await AccountDailyLogin.getAccountLogin(startDateStr, endDateStr);
        let totalDay: number = Math.floor((endDate - startDate) / Config.OneDay) + 1;
        let resultList: Array<object> = []
        for (let i = 0; i < totalDay; i++) {
            let defaultTime: Date = new Date(startDate)
            defaultTime.setHours(0)
            defaultTime.setMinutes(0)
            defaultTime.setSeconds(0)
            let obj: object = {
                "date": DateUtil.formatDateStr3(defaultTime.getTime() + Config.OneDay * i)
            }

            let count: number = 0
            for (let mm = 0; mm < list.length; mm++) {
                let date_stampDate: Date = new Date(list[mm]["date"])
                if (DateUtil.formatDateStr3(date_stampDate.getTime()) == obj["date"]) {
                    count++
                }
            }
            obj["count"] = count
            resultList[i] = obj
        }
        respModel.data = resultList
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_account_keep(req, resp, data: object, ip: string) {
        let searchTime: Array<number> = data["searchTime"]
        let totalDay: number = Math.floor((searchTime[1] - searchTime[0]) / Config.OneDay) + 1;
        let searchLoginStartTime: number = Math.floor(searchTime[0])
        let searchLoginEndTime: number = Math.floor(searchTime[1] + Config.OneDay * 30)
        let startTimeStr: string = DateUtil.formatDateStr3(searchTime[0])
        let endTimeStr: string = DateUtil.formatDateStr3(searchTime[1])
        let loginList: Array<any> = await AccountDailyLogin.getAccountLogin(DateUtil.formatDateStr3(searchLoginStartTime), DateUtil.formatDateStr3(searchLoginEndTime));
        let registerList: Array<any> = await AccountDailyRegister.getAccountRegister(startTimeStr, endTimeStr)
        let resultList: Array<object> = [

        ]

        for (let i = 0; i < totalDay; i++) {
            let defaultTime: Date = new Date(searchTime[1])
            defaultTime.getDate()
            defaultTime.setHours(0)
            defaultTime.setMinutes(0)
            defaultTime.setSeconds(0)
            let obj: object = {
                "date":DateUtil.formatDateStr3(defaultTime.getTime() - i * Config.OneDay)
            }
            let registerNum: number = 0
            let keepuser2: number = 0;
            let keepuser3: number = 0;
            let keepuser5: number = 0;
            let keepuser7: number = 0;
            let keepuser10: number = 0;
            let keepuser15: number = 0
            let keepuser30: number = 0;
            let keepuser60: number = 0;
            for (let mm = 0; mm < registerList.length; mm++) {
                let registerObj: object = registerList[mm];
                let date_stampDate: Date = new Date(registerObj["date"])
                if (obj["date"] == DateUtil.formatDateStr3(date_stampDate.getTime())) {
                    registerNum++;
                    let date2: number = (obj["date"] + Config.OneDay)
                    let date3: number = (obj["date"] + Config.OneDay * 2)
                    let date5: number = (obj["date"] + Config.OneDay * 4)
                    let date7: number = (obj["date"] + Config.OneDay * 6)
                    let date10: number = (obj["date"] + Config.OneDay * 9)
                    let date15: number = (obj["date"] + Config.OneDay * 14)
                    let date30: number = (obj["date"] + Config.OneDay * 29)
                    let date60: number = (obj["date"] + Config.OneDay * 59)

                    for (let nn = 0; nn < loginList.length; nn++) {
                        let obj: object = loginList[nn];
                        let date_stampDate: Date = new Date(obj["date_stamp"])
                        if (Math.floor(date_stampDate.getTime()) == Math.floor(date2) && registerObj["user_id"] == obj["user_id"]) {
                            keepuser2++;
                        }
                        if (Math.floor(date_stampDate.getTime()) == Math.floor(date3) && registerObj["user_id"] == obj["user_id"]) {
                            keepuser3++;
                        }
                        if (Math.floor(date_stampDate.getTime()) == Math.floor(date5) && registerObj["user_id"] == obj["user_id"]) {
                            keepuser5++;
                        }
                        if (Math.floor(date_stampDate.getTime()) == Math.floor(date7) && registerObj["user_id"] == obj["user_id"]) {
                            keepuser7++;
                        }
                        if (Math.floor(date_stampDate.getTime()) == Math.floor(date10 ) && registerObj["user_id"] == obj["user_id"]) {
                            keepuser10++;
                        }
                        if (Math.floor(date_stampDate.getTime()) == Math.floor(date15 ) && registerObj["user_id"] == obj["user_id"]) {
                            keepuser15++;
                        }
                        if (Math.floor(date_stampDate.getTime()) == Math.floor(date30 ) && registerObj["user_id"] == obj["user_id"]) {
                            keepuser30++;
                        }

                        if (Math.floor(date_stampDate.getTime() ) == Math.floor(date60 ) && registerObj["user_id"] == obj["user_id"]) {
                            keepuser60++;
                        }
                    }
                }
            }
            obj["registerNum"] = registerNum
            obj["keepuser2"] = keepuser2
            obj["keepuser3"] = keepuser3
            obj["keepuser5"] = keepuser5
            obj["keepuser7"] = keepuser7
            obj["keepuser10"] = keepuser10
            obj["keepuser15"] = keepuser15
            obj["keepuser30"] = keepuser30
            obj["keepuser60"] = keepuser60
            resultList.push(obj)
        }
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = resultList
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_user_list(req, resp, data: object, ip: string) {
        let pagenum: number = data["pagenum"]
        let pagesize: number = data["pagesize"]
        let respModel: ResponseModel = new ResponseModel()
        let resultObj: object = {
        }
        resultObj["users"] = await UserDao.get_user_list(pagenum, pagesize)
        resultObj["count"] = await UserDao.getUserNum()
        respModel.data = resultObj
        resp.end(JSON.stringify(respModel));
    }


    private async on_get_user_normal_daili_list(req, resp, data: object, ip: string) {
        let pagenum: number = data["pagenum"]
        let pagesize: number = data["pagesize"]
        let respModel: ResponseModel = new ResponseModel()
        let resultObj: object = {
        }
        let users: Array<object> = await UserDao.get_user_normal_daili_list(pagenum, pagesize)
        for (let i = 0; i < users.length; i++) {
            let count: number = await UserDao.get_normal_daili_xiaji_num(users[i]["userid"])
            users[i]["xiaji"] = count
        }
        resultObj["users"] = users
        resultObj["count"] = await UserDao.get_user_normal_daili_count()
        respModel.data = resultObj
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_user_qudao_daili_list(req, resp, data: object, ip: string) {
        let pagenum: number = data["pagenum"]
        let pagesize: number = data["pagesize"]
        let respModel: ResponseModel = new ResponseModel()
        let resultObj: object = {
        }
        let users: Array<object> = await UserDao.get_user_qudao_daili_list(pagenum, pagesize)
        for (let i = 0; i < users.length; i++) {
            let count: number = await UserDao.get_normal_daili_xiaji_num(users[i]["userid"])
            users[i]["xiaji"] = count
        }
        resultObj["users"] = users
        resultObj["count"] = await UserDao.get_user_qudao_daili_count()
        respModel.data = resultObj
        resp.end(JSON.stringify(respModel));
    }


    private async on_get_user_info(req, resp, data: object, ip: string) {
        let userid: number = data["userid"]
        let respModel: ResponseModel = new ResponseModel()
        let user: object = await UserDao.get_user_data_by_userid(userid)
        let resultObj: object = {
        }
        if (user) {
            resultObj["users"] = [user]
        } else {
            resultObj["users"] = []
        }
        respModel.data = resultObj
        resp.end(JSON.stringify(respModel));
    }

    private async on_charge_by_gm(req, resp, data: object, ip: string, user: GmUserModel) {
        let userid: number = data["userid"]
        let num: number = data["num"]
        let type: string = data["type"]

        if (type == "gems") {
            let left_gems: number = await UserDao.addGems(userid, num)
            ServerManager.instance.notify_update_gems(userid)
            LogGemDao.add_user_gems_log(userid, num, user.userName, DateUtil.formatDateStr(DateUtil.now()), user.userName + "在管理后台增加了" + num + "钻石")
            LogServerHelper.log_add_user_gems_history(userid, num, left_gems, GameConfig.Gems_History_Reason.Gm_Add, user.userName + "在管理后台增加了" + num + "钻石")
        }
        else if (type == "coins") {
            let left_coins: number = await UserDao.addCoins(userid, num)
            ServerManager.instance.notify_update_coins(userid)
            LogCoinDao.add_user_coin_log(userid, num, user.userName, DateUtil.formatDateStr(DateUtil.now()), user.userName + "在管理后台增加了" + num + "金豆")
            LogServerHelper.log_add_user_coins_history(userid, num, left_coins, GameConfig.Coins_History_Reason.Gm_Add, user.userName + "在管理后台增加了" + num + "金豆")
        }
        // else if (type == "meilis") {
        //     let left_meili: number = await UserDao.addMeili(userid, num)
        //     ServerManager.instance.notify_update_meili(userid)
        //     LogServerHelper.log_add_user_meilis_history(userid, num, left_meili, GameConfig.Meilis_History_Reason.Gm_Add, user.userName + "在管理后台增加了" + num + "魅力值")
        // }
        // else if (type == "income") {
        //     let left_income: number = await UserDao.add_income(userid, num)
        //     ServerManager.instance.notify_update_income(userid)
        //     LogServerHelper.log_add_user_income_history(userid, num, left_income, GameConfig.Income_History_Reason.Gm_Add, user.userName + "在管理后台增加了" + num + "未兑换金豆")
        // }
        let respModel: ResponseModel = new ResponseModel()
        resp.end(JSON.stringify(respModel));
    }

    private async on_fengjin_user(req, resp, data: object, ip: string) {
        let userid: number = data["userid"]
        let state: number = data["state"]
        await UserDao.setState(userid, state)
        let respModel: ResponseModel = new ResponseModel()
        resp.end(JSON.stringify(respModel));
    }

    private async on_set_normal_daili(req, resp, data: object, ip: string) {
        let userid: number = data["userid"]
        let lv: number = data["lv"]
        await UserDao.set_lv(userid, lv)
        await UserDao.clearInvite(userid)
        let respModel: ResponseModel = new ResponseModel()
        resp.end(JSON.stringify(respModel));
    }

    private async on_set_qudao_daili(req, resp, data: object, ip: string) {
        let userid: number = data["userid"]
        let qudaodaili: number = data["qudaodaili"]
        await UserDao.set_qudaodaili(userid, qudaodaili)
        let respModel: ResponseModel = new ResponseModel()
        resp.end(JSON.stringify(respModel));
    }

    private async on_req_invite_list(req, resp, data: object, ip: string) {

    }

    private async on_get_log_gem_date(req, resp, data: object, ip: string, user: GmUserModel) {
        let startTime: number = data["startTime"]
        let endTime: number = data["endTime"]
        let startTimeStr: string = DateUtil.formatDateStr(startTime)
        let endTimeStr: string = DateUtil.formatDateStr(endTime)
        let list: Array<object> = await LogGemDao.get_log_gem(startTimeStr, endTimeStr)
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = list
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_log_gem_week(req, resp, data: object, ip: string, user: GmUserModel) {
        let searchDate: number = data["searchDate"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let endDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 7)
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let endTime: string = DateUtil.formatDateStr(endDate.getTime())
        let list: Array<object> = await LogGemDao.get_log_gem(startTime, endTime)
        let resultList: Array<object> = []
        let dateArr: Array<string> = []
        for (let i = 0; i < 7; i++) {
            tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i)
            let tempDateStr: string = DateUtil.formatDateStr3(tempDate.getTime())
            let obj: object = {
                "date": tempDateStr,
                "gems": 0,
            }
            resultList[i] = obj
            dateArr[i] = tempDateStr
        }
        for (let j = 0; j < list.length; j++) {
            let data: object = list[j]
            let tempDateStr: string = DateUtil.formatDateStr3(new Date(data["time"]).getTime())
            let index: number = dateArr.indexOf(tempDateStr)
            if (index != -1) {
                let obj: object = resultList[index]
                obj["gems"] += data["gems"]
            }
        }

        let respModel: ResponseModel = new ResponseModel()
        respModel.data = resultList
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_log_gem_month(req, resp, data: object, ip: string, user: GmUserModel) {
        let searchDate: number = data["searchDate"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let endDate: Date
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let resultList: Array<object> = []
        let dateArr: Array<string> = []
        for (let i = 0; i < 31; i++) {
            tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i)
            if (tempDate.getMonth() == startDate.getMonth()) {
                endDate = tempDate;
                let tempDateStr: string = DateUtil.formatDateStr3(tempDate.getTime())
                let obj: object = {
                    "date": tempDateStr,
                    "gems": 0,
                }
                resultList[i] = obj
                dateArr[i] = tempDateStr
            } else {
                break
            }
        }

        let endTime: string = DateUtil.formatDateStr(endDate.getTime())
        let list: Array<object> = await LogGemDao.get_log_gem(startTime, endTime)

        for (let j = 0; j < list.length; j++) {
            let data: object = list[j]
            let tempDateStr: string = DateUtil.formatDateStr3(new Date(data["time"]).getTime())
            let index: number = dateArr.indexOf(tempDateStr)
            if (index != -1) {
                let obj: object = resultList[index]
                obj["gems"] += data["gems"]
            }
        }
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = resultList
        resp.end(JSON.stringify(respModel));
    }


    private async on_get_log_coin_date(req, resp, data: object, ip: string, user: GmUserModel) {
        let startTime: number = data["startTime"]
        let endTime: number = data["endTime"]
        let startTimeStr: string = DateUtil.formatDateStr(startTime)
        let endTimeStr: string = DateUtil.formatDateStr(endTime)
        let list: Array<object> = await LogCoinDao.get_log_coin(startTimeStr, endTimeStr)
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = list
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_log_coin_week(req, resp, data: object, ip: string, user: GmUserModel) {
        let searchDate: number = data["searchDate"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let endDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 7)
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let endTime: string = DateUtil.formatDateStr(endDate.getTime())
        let list: Array<object> = await LogCoinDao.get_log_coin(startTime, endTime)
        let resultList: Array<object> = []
        let dateArr: Array<string> = []
        for (let i = 0; i < 7; i++) {
            tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i)
            let tempDateStr: string = DateUtil.formatDateStr3(tempDate.getTime())
            let obj: object = {
                "date": tempDateStr,
                "coin": 0,
            }
            resultList[i] = obj
            dateArr[i] = tempDateStr
        }
        for (let j = 0; j < list.length; j++) {
            let data: object = list[j]
            let tempDateStr: string = DateUtil.formatDateStr3(new Date(data["time"]).getTime())
            let index: number = dateArr.indexOf(tempDateStr)
            if (index != -1) {
                let obj: object = resultList[index]
                obj["coin"] += data["coin"]
            }
        }

        let respModel: ResponseModel = new ResponseModel()
        respModel.data = resultList
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_log_coin_month(req, resp, data: object, ip: string, user: GmUserModel) {
        let searchDate: number = data["searchDate"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let endDate: Date
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let resultList: Array<object> = []
        let dateArr: Array<string> = []
        for (let i = 0; i < 31; i++) {
            tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i)
            if (tempDate.getMonth() == startDate.getMonth()) {
                endDate = tempDate;
                let tempDateStr: string = DateUtil.formatDateStr3(tempDate.getTime())
                let obj: object = {
                    "date": tempDateStr,
                    "coin": 0,
                }
                resultList[i] = obj
                dateArr[i] = tempDateStr
            } else {
                break
            }
        }

        let endTime: string = DateUtil.formatDateStr(endDate.getTime())
        let list: Array<object> = await LogCoinDao.get_log_coin(startTime, endTime)

        for (let j = 0; j < list.length; j++) {
            let data: object = list[j]
            let tempDateStr: string = DateUtil.formatDateStr3(new Date(data["time"]).getTime())
            let index: number = dateArr.indexOf(tempDateStr)
            if (index != -1) {
                let obj: object = resultList[index]
                obj["coin"] += data["coin"]
            }
        }
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = resultList
        resp.end(JSON.stringify(respModel));
    }

    private async on_game_date_charge_data(req, resp, data: object, ip: string) {
        let searchDate: number = data["searchDate"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let endDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1)
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let endTime: string = DateUtil.formatDateStr(endDate.getTime())
        let list: Array<object> = await ChargeDao.game_date_charge_data(startTime, endTime)
        for (let i = 0; i < list.length; i++) {
            let item: object = list[i]
            if (item["type"] == GoodConfig.GoodAddType.gems) {
                item["gems"] = item["chargenum"]
                item["coins"] = 0
            } else {
                item["gems"] = 0
                item["coins"] = item["chargenum"]
            }
        }
        Logger.log("on_game_date_charge_data===", searchDate, list)
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = list
        resp.end(JSON.stringify(respModel));
    }

    private async on_game_week_charge_data(req, resp, data: object, ip: string) {
        let searchDate: number = data["searchDate"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let endDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 7)
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let endTime: string = DateUtil.formatDateStr(endDate.getTime())
        let list: Array<object> = await ChargeDao.game_week_charge_data(startTime, endTime)
        let resultList: Array<object> = []
        let dateArr: Array<string> = []
        for (let i = 0; i < 7; i++) {
            tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i)
            let tempDateStr: string = DateUtil.formatDateStr3(tempDate.getTime())
            let obj: object = {
                "date": tempDateStr,
                "rmb": 0,
                "gems": 0,
                "coins": 0,
            }
            resultList[i] = obj
            dateArr[i] = tempDateStr
        }

        for (let j = 0; j < list.length; j++) {
            let data: object = list[j]
            let tempDateStr: string = DateUtil.formatDateStr3(new Date(data["pay_time"]).getTime())
            let index: number = dateArr.indexOf(tempDateStr)
            if (index != -1) {
                let obj: object = resultList[index]
                obj["rmb"] += data["rmb"]
                if (data["type"] == GoodConfig.GoodAddType.gems) {
                    obj["gems"] += data["chargenum"]
                } else {
                    obj["coins"] += data["chargenum"]
                }
            }
        }

        let respModel: ResponseModel = new ResponseModel()
        respModel.data = resultList
        resp.end(JSON.stringify(respModel));
    }

    private async on_game_month_charge_data(req, resp, data: object, ip: string) {
        let searchDate: number = data["searchDate"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let endDate: Date
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let resultList: Array<object> = []
        let dateArr: Array<string> = []
        for (let i = 0; i < 31; i++) {
            tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i)
            if (tempDate.getMonth() == startDate.getMonth()) {
                endDate = tempDate;
                let tempDateStr: string = DateUtil.formatDateStr3(tempDate.getTime())
                let obj: object = {
                    "date": tempDateStr,
                    "rmb": 0,
                    "gems": 0,
                    "coins": 0,
                }
                resultList[i] = obj
                dateArr[i] = tempDateStr
            } else {
                break
            }
        }

        let endTime: string = DateUtil.formatDateStr(endDate.getTime())
        let list: Array<object> = await ChargeDao.game_week_charge_data(startTime, endTime)

        for (let j = 0; j < list.length; j++) {
            let data: object = list[j]
            let tempDateStr: string = DateUtil.formatDateStr3(new Date(data["pay_time"]).getTime())
            let index: number = dateArr.indexOf(tempDateStr)
            if (index != -1) {
                let obj: object = resultList[index]
                obj["rmb"] += data["rmb"]
                if (data["type"] == GoodConfig.GoodAddType.gems) {
                    obj["gems"] += data["chargenum"]
                } else {
                    obj["coins"] += data["chargenum"]
                }
            }
        }
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = resultList
        resp.end(JSON.stringify(respModel));

    }

    private async on_get_user_spend(req, resp, data: object, ip: string) {
        let respModel: ResponseModel = new ResponseModel()
        let searchDate: number = data["searchDate"]
        let timetype: string = data["timetype"]
        let kind: string = data["kind"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let endDate: Date
        let endTime: string
        let list: Array<object>
        let resultList: Array<object> = []
        let dateArr: Array<string> = []
        if (timetype == "date") {
            endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1)
            endTime = DateUtil.formatDateStr(endDate.getTime())
            list = await User_Spend_DailyDao.get_user_spend_daily(kind, startTime, endTime)
            Logger.log("on_get_user_spend========", list)
            respModel.data = list
        }
        else if (timetype == "week" || timetype == "month") {

            if (timetype == "week") {
                endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 7)


                for (let i = 0; i < 7; i++) {
                    tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i)
                    let tempDateStr: string = DateUtil.formatDateStr3(tempDate.getTime())
                    let obj: object = {
                        "date": tempDateStr,
                        "gems": 0,
                        "coins": 0,
                    }
                    resultList[i] = obj
                    dateArr[i] = tempDateStr
                }
            } else {
                for (let i = 0; i < 31; i++) {
                    tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i)
                    if (tempDate.getMonth() == startDate.getMonth()) {
                        endDate = tempDate;
                        let tempDateStr: string = DateUtil.formatDateStr3(tempDate.getTime())
                        let obj: object = {
                            "date": tempDateStr,
                            "gems": 0,
                            "coins": 0,
                        }
                        resultList[i] = obj
                        dateArr[i] = tempDateStr
                    } else {
                        break
                    }
                }
            }
            endTime = DateUtil.formatDateStr(endDate.getTime()) + Config.OneDay
            list = await User_Spend_DailyDao.get_user_spend_by_date(startTime, endTime)

            for (let j = 0; j < list.length; j++) {
                let data: object = list[j]
                let tempDateStr: string = DateUtil.formatDateStr3(new Date(data["date"]).getTime())
                let index: number = dateArr.indexOf(tempDateStr)
                if (index != -1) {
                    let obj: object = resultList[index]
                    obj["gems"] += data["gems"]
                    obj["coins"] += data["coins"]
                }
            }
            respModel.data = resultList
        }
        resp.end(JSON.stringify(respModel));
    }


    private async on_get_room_statistics(req, resp, data: object, ip: string) {
        let respModel: ResponseModel = new ResponseModel()
        let searchDate: number = data["searchDate"]
        let timetype: string = data["timetype"]
        let clubid: number = data["clubid"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let endDate: Date
        let endTime: string
        let list: Array<object>
        let resultList: Array<object> = []
        let dateArr: Array<string> = []
        if (timetype == "date") {
            endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1)
            endTime = DateUtil.formatDateStr(endDate.getTime())
            list = await RoomStatisticsDao.get_statistics(clubid, startTime, endTime)
            respModel.data = list
        }
        else if (timetype == "week" || timetype == "month") {
            if (timetype == "week") {
                endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 7)
                for (let i = 0; i < 7; i++) {
                    tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i)
                    let tempDateStr: string = DateUtil.formatDateStr3(tempDate.getTime())
                    let obj: object = {
                        "date": tempDateStr,
                        "ju": 0,
                    }
                    resultList[i] = obj
                    dateArr[i] = tempDateStr
                }
            } else {
                for (let i = 0; i < 31; i++) {
                    tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i)
                    if (tempDate.getMonth() == startDate.getMonth()) {
                        endDate = tempDate;
                        let tempDateStr: string = DateUtil.formatDateStr3(tempDate.getTime())
                        let obj: object = {
                            "date": tempDateStr,
                            "ju": 0,
                        }
                        resultList[i] = obj
                        dateArr[i] = tempDateStr
                    } else {
                        break
                    }
                }
            }
            endTime = DateUtil.formatDateStr(endDate.getTime()) + Config.OneDay
            list = await RoomStatisticsDao.get_statistics(clubid, startTime, endTime)

            for (let j = 0; j < list.length; j++) {
                let data: object = list[j]
                let tempDateStr: string = DateUtil.formatDateStr3(new Date(data["time"]).getTime())
                let index: number = dateArr.indexOf(tempDateStr)
                if (index != -1) {
                    let obj: object = resultList[index]
                    obj["ju"] += 1

                }
            }
            respModel.data = resultList
        }
        resp.end(JSON.stringify(respModel));
    }


    private async on_update_system_setting(req, resp, data: object, ip: string) {
        let setting_key: string = data["setting_key"]
        let setting_value: string = data["setting_value"]
        let specailList: Array<number> = GameConfig.specialList

    }

    private async on_get_system_setting(req, resp, data: object, ip: string) {
        let setting_key: string = data["setting_key"]
        let setting_value: string = await SystemSettingDao.get_system_setting(setting_key)
        let specailList: Array<number> = GameConfig.specialList
    }

    private async on_get_notice(req, resp, data: object, ip: string) {
        let notice: string = await SystemSettingDao.get_notice()
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = notice
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_choushui(req, resp, data: object, ip: string) {
        let choushui: string = await SystemSettingDao.get_choushui()
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = choushui
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_gems_detail(req, resp, data: object, ip: string) {
        let searchDate: number = data["searchDate"]
        let pagenum: number = data["pagenum"]
        let pagesize: number = data["pagesize"]
        let userid: number = data["userid"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let endDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1)
        let endTime: string = DateUtil.formatDateStr(endDate.getTime())
        let respModel: ResponseModel = await User_Gems_HistoryDao.get_gems_detail(pagenum, pagesize, userid, startTime, endTime)
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_coins_detail(req, resp, data: object, ip: string) {
        let searchDate: number = data["searchDate"]
        let pagenum: number = data["pagenum"]
        let pagesize: number = data["pagesize"]
        let userid: number = data["userid"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let endDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1)
        let endTime: string = DateUtil.formatDateStr(endDate.getTime())
        let respModel: ResponseModel = await User_Coins_HistoryDao.get_coins_detail(pagenum, pagesize, userid, startTime, endTime)
        resp.end(JSON.stringify(respModel));
    }

    private async on_get_meilis_detail(req, resp, data: object, ip: string) {
        let searchDate: number = data["searchDate"]
        let pagenum: number = data["pagenum"]
        let pagesize: number = data["pagesize"]
        let userid: number = data["userid"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let startTime: string = DateUtil.formatDateStr(startDate.getTime())
        let endDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1)
        let endTime: string = DateUtil.formatDateStr(endDate.getTime())
        let respModel: ResponseModel = await User_Meilis_HistoryDao.get_meilis_detail(pagenum, pagesize, userid, startTime, endTime)
        resp.end(JSON.stringify(respModel));

    }

    private async on_get_daily_resource(req, resp, data: object, ip: string) {
        let resultList: Array<object> = await Daily_ResourceDao.get_daily_resource()
        let respModel: ResponseModel = new ResponseModel()
        respModel.data = resultList
        resp.end(JSON.stringify(respModel));
    }

    private async set_allserver_status(req, resp, data: object, ip: string) {
        let status: number = data["status"]
        ServerConfig.nowServerConfig.status = status
        ServerManager.instance.set_allserver_status(status)
        let respModel: ResponseModel = new ResponseModel()
        resp.end(JSON.stringify(respModel));
    }

    private async set_gameserver_status(req, resp, data: object, ip: string) {
        let gameType: number = data["gameType"]
        let status: number = data["status"]

        let respModel: ResponseModel = new ResponseModel()
        resp.end(JSON.stringify(respModel));
    }

    private async get_gameserver_status(req, resp, data: object, ip: string) {
        let gameType: number = data["gameType"]

        // let status: number = 0
        // let server: ServerConfig
        // if (gameType == GameConfig.Game_Type.huanghua_mj) {
        //     server = ServerConfig.huanghua_mj_server_list[0]
        // }
        // else if (gameType == GameConfig.Game_Type.ddz) {
        //     server = ServerConfig.ddz_server_list[0]
        // }
        // else if (gameType == GameConfig.Game_Type.jianziding) {
        //     server = ServerConfig.jianziding_server_list[0]
        // }
        // else if (gameType == GameConfig.Game_Type.cangxian_mj) {
        //     server = ServerConfig.cangxian_mj_server_list[0]
        // }
        // else if (gameType == GameConfig.Game_Type.paodekuai) {
        //     server = ServerConfig.paodekuai_server_list[0]
        // }
        // else if (gameType == GameConfig.Game_Type.dazhonger_mj) {
        //     server = ServerConfig.dazhonger_mj_server_list[0]
        // }
        // let respModel: ResponseModel = new ResponseModel()
        // respModel.data = server.status
        // resp.end(JSON.stringify(respModel));
    }


    private async get_gm_server_status(req, resp, data: object, ip: string) {
        let respModel: ResponseModel = new ResponseModel()
        let arr: Array<number> = [
            ServerConfig.nowServerConfig.status,
            // ServerConfig.huanghua_mj_server_list[0].status,
            // ServerConfig.ddz_server_list[0].status,
            // ServerConfig.jianziding_server_list[0].status,
            // ServerConfig.cangxian_mj_server_list[0].status,
            // ServerConfig.paodekuai_server_list[0].status,
            // ServerConfig.dazhonger_mj_server_list[0].status,
        ]
        respModel.data = arr
        resp.end(JSON.stringify(respModel));
    }

    private async on_create_ziyou_room_template(req, resp, data: object, ip: string) {
        let roomObj: object = data["roomObj"]
        let respModel: ResponseModel = new ResponseModel()
        let gameType: number = roomObj["gameType"]
        let level: number = roomObj["level"]
        // let roomJinbiConfig: RoomJinbiConfig = RoomJinbiConfig.getConfigByGameAndLevel(gameType, RoomConfig.Room_Type.Ziyou, level)
        // roomObj["enterMin"] = roomJinbiConfig.enterMin
        // roomObj["cost"] = roomJinbiConfig.serve
        // roomObj["difen"] = roomJinbiConfig.difen
        // roomObj["minCharge"] = roomJinbiConfig.minCharge

        // let serverConfig: ServerConfig = ServerConfig.randomGameServer(gameType)
        // let roomModel: RoomModel = new RoomModel();
        // roomModel.roomType = RoomConfig.Room_Type.Ziyou
        // roomModel.room_id = RoomModel.generateRoomId()
        // roomModel.creator = 0 //gm创建
        // roomModel.create_time = DateUtil.now()
        // roomModel.state = RoomConfig.Room_State_Type.Normal
        // roomModel.gameType = gameType;
        // roomModel.server_id = serverConfig.id;
        // roomModel.conf = roomObj
        // roomModel.game_info.game_state = 0
        // let dbSuc: boolean = await RoomTemplateDao.insert_room_template(roomObj["name"], 0, 0, roomObj, RoomConfig.Room_Type.Ziyou)
        // if (dbSuc) {
        //     ServerManager.instance.insertRoomTemplateModel()
        //     respModel.code = ErrorCode.Code.Suc
        // } else {
        //     respModel.code = ErrorCode.Code.Db_Error
        //     respModel.msg = "插入房间模板时出错"
        // }
        // resp.end(JSON.stringify(respModel));
    }

    private async on_get_ziyou_room_template(req, resp, data: object, ip: string) {
        let gameType: number = data["gameType"]
        let respModel: ResponseModel = new ResponseModel()
        let resultList: Array<RoomTemplateModel> = []

        let roomObjList: Array<object> = await RoomTemplateDao.get_ziyou_room_template(gameType)
        for (let i = 0; i < roomObjList.length; i++) {
            // let room: RoomTemplateModel = RoomTemplateModel.initOneRoomTemplate(roomObjList[i])
            // resultList.push(room)
        }
        respModel.data = resultList
        resp.end(JSON.stringify(respModel));
    }

    private async on_delete_ziyou_room_template(req, resp, data: object, ip: string) {
        let id: number = data["id"]
        let respModel: ResponseModel = new ResponseModel()
        let dbSuc: boolean = await RoomTemplateDao.delete_room_template(id)
        if (dbSuc) {
            ServerManager.instance.deleteRoomTemplate(id)
        } else {
            respModel.code = ErrorCode.Code.Fail
            respModel.msg = "删除失败"
        }
        resp.end(JSON.stringify(respModel));

    }

    private async on_clear_weihu_room(req, resp, data: object, ip: string) {
        let respModel: ResponseModel = new ResponseModel()
        let dbSuc: boolean = await RoomDao.clear_all_room()
        if (dbSuc) {

        } else {
            respModel.code = ErrorCode.Code.Fail
            respModel.msg = "清理失败"
        }
        resp.end(JSON.stringify(respModel));
    }

    private async fix_club_top(req, resp, data: object, ip: string) {
        let respModel: ResponseModel = new ResponseModel()
        let clubid: number = data["clubid"]
        let userid: number = data["userid"]
        let key: string = data["key"]
        let value: number = data["value"]
        let dateStr: string = data["dateStr"]
        let dbSuc: boolean = await ClubTopDao.updateTop(clubid, userid, key, value, dateStr)
        if (dbSuc) {

        } else {
            respModel.code = ErrorCode.Code.Fail
            respModel.msg = "修改失败"
        }
        resp.end(JSON.stringify(respModel));
    }

    private async kill_all_users(req, resp, data: object, ip: string) {
        let respModel: ResponseModel = new ResponseModel()
        ServerManager.instance.kill_all_users()
        resp.end(JSON.stringify(respModel));

        setTimeout(async () => {
            let dbSuc: boolean = await RoomDao.clear_all_room()
        }, 3000);
    }

    private async get_zhanji(req, resp, data: object, ip: string) {
        let respModel: ResponseModel = new ResponseModel()
        let searchDate: number = data["searchDate"]
        let tempDate: Date = new Date(searchDate)
        let startDate: Date = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())
        let pagenum: number = data["pagenum"]
        let pagesize: number = data["pagesize"]
        let userid: number = data["userid"]
        let gameType: number = data["gameType"]
        let result: Array<object> = await RoomResultDao.getResultByGameTypeAndUserid(gameType, userid, pagenum, pagesize, startDate.getTime())

        respModel.data = result
        resp.end(JSON.stringify(respModel));
    }

    private async get_zhanji_detail(req, resp, data: object, ip: string) {
        let respModel: ResponseModel = new ResponseModel()
        let gameResultId: number = data["gameResultId"]
        let result: Array<object> = await RoomVideoDao.getByGameResultId(gameResultId)
        respModel.data = result
        resp.end(JSON.stringify(respModel));
    }

    private async on_unbind(req, resp, data: object, ip: string) {

    }

}